package com.cap.dreamcircle.View;

import android.content.Context;
import android.view.ViewGroup;

import com.cap.dreamcircle.Common.RecyclerView.BaseItem;
import com.cap.dreamcircle.Common.RecyclerView.MultiTypeListAdapter;
import com.cap.dreamcircle.Model.Bean.FellowFansForbiddenEntity;
import com.cap.dreamcircle.View.Adapter.Item.FellowFansForbiddensItem;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by liucxu on 2017/10/18.
 */

public class FellowFansForbiddensAdapter extends MultiTypeListAdapter<FellowFansForbiddenEntity> {

    private List<FellowFansForbiddenEntity> datas = new ArrayList<>();
    private Context mContext;

    public FellowFansForbiddensAdapter(Context c, List<FellowFansForbiddenEntity> sources) {
        if (sources != null) {
            datas.clear();
            datas.addAll(sources);
            mContext = c;
        }
    }

    public void setDatas(List<FellowFansForbiddenEntity> sources) {
        if (sources != null) {
            datas.clear();
            datas.addAll(sources);
            notifyDataSetChanged();
        }
    }

    @Override
    public FellowFansForbiddenEntity getItem(int viewType, int position) {
        return datas.get(position);
    }

    @Override
    public BaseItem<FellowFansForbiddenEntity> createItemView(ViewGroup parent, int viewType) {
        return new FellowFansForbiddensItem(parent);
    }

    public void deleteItem(int position) {
        if ((position >= 0) && (datas.size() > 0)) {
            if (datas.size() - 1 >= position) {
                datas.remove(position);
                notifyItemRemoved(position);
                notifyItemRangeChanged(0,getItemCount());
            }
        }
    }

    @Override
    public int getItemCount() {
        return datas.size();
    }
}
